﻿using System.Drawing;
using System.Linq;
using System.Windows.Forms;

namespace StockLib.Indicator
{
    public partial class StockBBIIndicator : StockIndicator
    {
        public override void DrawGraphTitle(Graphics g, Rectangle rect)
        {
            int y = (rect.Top + rect.Bottom) / 2;
            int x = rect.Left;

            float[] ma = CalcOutput(indexEnd);
            string textOutput = string.Format("BBI:{0:#0}", ma[0]);
            TextRenderer.DrawText(g, textOutput, font, new Point(x, y), StockProfile.Colors.GraphTextColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
            x += TextRenderer.MeasureText(textOutput, font).Width;
        }

        public override void DrawGraphData(Graphics g)
        {
            int maDaysMax = maDays.Max();

            for (int index = indexStart; index <= indexEnd; index++)
            {
                if (index > maDaysMax)
                {
                    float[] ma = CalcOutput(index);
                    float[] maLast = CalcOutput(index - 1);

                    int xPos = GetXPos(index);
                    int xPosLast = GetXPos(index - 1);
                    int yPos = GetYPos(ma[0]);
                    int yPosLast = GetYPos(maLast[0]);
                    g.DrawLine(StockProfile.IndicatorPens[0], xPosLast, yPosLast, xPos, yPos);
                }
            }
        }
    }
}
